<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>欢迎使用房屋租赁系统</title>
</head>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
    $.ajax({
        "url" : "getUserSession",
        "method" : "GET"
    }).success(function(result){
        document.getElementById('id').value=result.data.id;
    })
</script>
<body>
<form id="form1" onsubmit="return false" action="##" >
    <input type="hidden" id="id" name="id">
    原密码<input type="text" id="oldPassword" name="oldPassword"></br>
    新密码<input type="text" id="newPassword" name="newPassword"></br>
    <input type="button" value="确认" onclick="updatePassword()">
</form>
</body>
<script>
    function updatePassword() {
        $.ajax({
            url: 'updatePassword',
            method: 'PUT',
            dataType: 'json',
            data: $('#form1').serialize(),
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.status == 200) {
                    alert(result.data);
                    if(result.data=="修改成功，即将返回登录页面"){
                        window.location.href = 'login.html';
                    }
                }
            },
            error: function () {
                alert("异常！");
            }
        })
    }
</script>


</html>